#ifndef DATABASE_MALLOC_H
#define DATABASE_MALLOC_H

#include "Alloc.hpp"

/**-----------------------------------------------------
 * 
 * new and delete operator reload
 * -----------------------------------------------------
*/
template<class T>
T* New(void) {
    T *object = (T*)DBServer::Database::Alloc::GetInstance()->New(sizeof(T));
    new (object) T();
    return object;
}

template<class T>
T* New(T&& t) {
    T *object = (T*)DBServer::Database::Alloc::GetInstance()->New(sizeof(T));
    new (object) T(std::forward<T>(t));
    return object;
}

template<class T>
T* New(T& t) {
    T *object = (T*)DBServer::Database::Alloc::GetInstance()->New(sizeof(T));
    new (object) T(std::forward<T>(t));
    return object;
}

template<class T>
void Delete(T *ptr) {
    printf("delete operator\n");
    ptr->~T();
    DBServer::Database::Alloc::GetInstance()->Delete((char*)ptr);
}

template<class T, class Arg>
T* New(Arg arg) {
    T *object = (T*)DBServer::Database::Alloc::GetInstance()->New(sizeof(T));
    new (object) T(std::forward<Arg>(arg));
    return object;
}

template<class T>
T* New(T* t) {
    T *object = (T*)DBServer::Database::Alloc::GetInstance()->New(sizeof(T));
    new (object) T(std::forward<T>(*t));
    return object;
}

#endif